/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief Image Conversions class
 * \author Antti Maula <antti.maula@tkk.fi>
 *
 */
#ifndef _MACI_INTERFACES_IMAGE_IMAGECONVERSION_HPP_
#define _MACI_INTERFACES_IMAGE_IMAGECONVERSION_HPP_
#include "ImageTypes.hpp"

namespace MaCI {
  namespace Image {
    
    class CImageConversion {
    public:

      CImageConversion();
      ~CImageConversion();
      CImageConversion(const CImageConversion &);
      CImageConversion &operator=(const CImageConversion &);

      bool ConvertImageData(const EImageDataType aSrcType, 
                            const EImageDataType aDestType,
                            unsigned int &aWidth, 
                            unsigned int &aHeight,
                            const unsigned char *aInputPtr, 
                            const unsigned int aInputSize,
                            unsigned char **aOutputPtrPtr,
                            unsigned int *aOutputSizePtr);
    private:
      unsigned char *iTemporary_buffer; ///< Temporary buffer for any operation requiring it.
      unsigned int iTemporary_buffer_size; ///< Size of temp buffer.
      
    private:
      void ReserveTemporary(const unsigned int aBytes);
      inline unsigned char *GetTemporaryBufferPtr(void) const;

      // Specialized converters.
      bool ConvertImageData_JPEG_to_RGB(unsigned int &aWidth, 
                                        unsigned int &aHeight,
                                        const unsigned char *aInputPtr, 
                                        const unsigned int aInputSize,
                                        unsigned char **aOutputPtrPtr,
                                        unsigned int *aOutputSizePtr);
      bool ConvertImageData_RGB_to_JPEG(const unsigned int aWidth, 
                                        const unsigned int aHeight,
                                        const unsigned char *aInputPtr, 
                                        const unsigned int aInputSize,
                                        unsigned char **aOutputPtrPtr,
                                        unsigned int *aOutputSizePtr);
      
      bool ConvertImageData_RGB_to_PNG(const unsigned int aWidth, 
                                       const unsigned int aHeight,
                                       const unsigned char *aInputPtr, 
                                       const unsigned int aInputSize,
                                       unsigned char **aOutputPtrPtr,
                                       unsigned int *aOutputSizePtr);
      bool ConvertImageData_PNG_to_RGB(unsigned int &aWidth, 
                                       unsigned int &aHeight,
                                       const unsigned char *aInputPtr, 
                                       const unsigned int aInputSize,
                                       unsigned char **aOutputPtrPtr,
                                       unsigned int *aOutputSizePtr);

      bool ConvertImageData_YUV420P_to_JPEG(const unsigned int aWidth, 
                                            const unsigned int aHeight,
                                            const unsigned char *aInputPtr, 
                                            const unsigned int aInputSize,
                                            unsigned char **aOutputPtrPtr,
                                            unsigned int *aOutputSizePtr);
      bool ConvertImageData_YUV422_to_JPEG(const unsigned int aWidth, 
                                           const unsigned int aHeight,
                                           const unsigned char *aInputPtr, 
                                           const unsigned int aInputSize,
                                           unsigned char **aOutputPtrPtr,
                                           unsigned int *aOutputSizePtr);

      bool ConvertImageData_YUV422_to_RGB(const unsigned int aWidth, 
                                           const unsigned int aHeight,
                                           const unsigned char *aInputPtr, 
                                           const unsigned int aInputSize,
                                           unsigned char **aOutputPtrPtr,
                                           unsigned int *aOutputSizePtr);


      bool ConvertImageData_Greyscale_to_JPEG(const unsigned int aWidth, 
                                              const unsigned int aHeight,
                                              const unsigned char *aInputPtr, 
                                              const unsigned int aInputSize,
                                              unsigned char **aOutputPtrPtr,
                                              unsigned int *aOutputSizePtr);
      bool ConvertImageData_YUYV_to_JPEG(const unsigned int aWidth, 
                                         const unsigned int aHeight,
                                         const unsigned char *aInputPtr, 
                                         const unsigned int aInputSize,
                                         unsigned char **aOutputPtrPtr,
                                         unsigned int *aOutputSizePtr);

    };
    
    //*************************************************************************
    //*************************************************************************
    //*************************************************************************
    //*************************************************************************
    inline unsigned char *CImageConversion::GetTemporaryBufferPtr(void) const
    {
      return iTemporary_buffer;
    }
    //*************************************************************************
    //*************************************************************************
  }
}

#endif
